
const app = getApp()

Page({
  data: {
    taskContent: '',
    title: '',
    taskEndDateStr: '',
    taskType: '',
    id: null,
    wh:0
  },
  onShow: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          "wh": res.windowHeight - 48 -wx.getSystemInfoSync().statusBarHeight
        })
      }
    })
  },
  goBack: function(){
    wx.navigateBack({
      delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
    });
  },
  onLoad: function (options) {
    var id = options.id;
    this.setData({
      id: id
    })
    var that = this;
    wx.request({
      url: 'https://www.xinhuo.site/api/learn/detail',
      data: {
        id: id
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.taskContent = res.data.record.taskContent;
          that.data.title = res.data.record.title;
          that.data.taskEndDateStr = res.data.record.taskEndDateStr;
          that.data.taskType = res.data.record.taskType;
          that.setData({
            title: that.data.title,
            taskContent: that.data.taskContent,
            taskEndDateStr: that.data.taskEndDateStr,
            taskType: that.data.taskType
          })
        }
      }
    })
  },
  learn: function () {
    var that = this;
    wx.request({
      url: 'https://www.xinhuo.site/api/learn/updateLearnResult',
      data: {
        taskId: this.data.id,
        userId: app.globalData.userId,
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        wx.navigateBack({
          delta: 1
        });
      }
    })
  }
})
